﻿package view.popup.control
{
    import com.core.*;
    import com.sh.game.global.*;
    import com.sh.game.net.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.utils.*;
    import manager.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import plugin.instance.*;
    import plugin.instances.*;
    import plugin.juezhan.model.*;
    import uiresource.popup.*;
    import view.mornExtends.*;
    import vo.*;

    public class FBDropCtrl extends HdpUI implements IDialogUI
    {
        private var canceled:Boolean = false;
        private var nextmapid:int = 0;
        private var _timeID:uint = 0;
        private var _items:Array;
        private var instance:Object;

        public function FBDropCtrl()
        {
            this._items = new Array();
            return;
        }// end function

        public function show(param1:Object) : void
        {
            var _loc_7:Object = null;
            var _loc_9:Object = null;
            var _loc_12:Object = null;
            var _loc_13:Object = null;
            var _loc_14:int = 0;
            var _loc_2:* = param1[0];
            var _loc_3:* = param1[1];
            var _loc_4:int = 0;
            if (param1[2])
            {
                _loc_4 = param1[2];
                if (_loc_4 == 16008)
                {
                    if (param1[3] != true)
                    {
                        ModelProxy.change("data", "yhfgDelay", param1);
                        return;
                    }
                }
                _loc_12 = ConfigDictionary.data.instance;
                _loc_13 = _loc_12[_loc_4];
                if (_loc_13)
                {
                    if (_loc_13.type == InstanceType.ZHUANSHENG)
                    {
                        ModelProxy.change("plugin", "open", {target:"role", data:2});
                    }
                }
            }
            this.canceled = false;
            this.visible = true;
            var _loc_5:* = new Array();
            var _loc_6:* = ConfigDictionary.data.item;
            this._items.length = 0;
            var _loc_8:* = this.localToGlobal(new Point(btn.x, btn.y));
            for each (_loc_9 in _loc_2.source)
            {
                
                _loc_14 = 0;
                if (_loc_6[_loc_9[0]])
                {
                    _loc_7 = ItemObject.create(_loc_6[_loc_9[0]]);
                    _loc_14 = int(_loc_9[1]);
                }
                if (_loc_7)
                {
                    _loc_7.count = _loc_14;
                    _loc_5.push(_loc_7);
                    this._items.push({icon:_loc_7.icon, x:_loc_8.x, y:_loc_8.y});
                }
            }
            if (this.instance == null)
            {
                this.instance = ConfigDictionary.data.instance;
            }
            this.nextmapid = 0;
            var _loc_10:* = this.instance[_loc_4].action_success;
            var _loc_11:* = this.instance[_loc_4].action_success.split("#");
            if (this.instance[_loc_4].action_success.split("#").length == 2 && _loc_11[0] == 5)
            {
                this.nextmapid = _loc_11[1];
                btn.label = "退出";
                btn.visible = false;
                btn1.visible = true;
                btn2.visible = true;
                this.closeBtn.visible = false;
                if (this._timeID)
                {
                    clearTimeout(this._timeID);
                }
                this._timeID = setTimeout(this.gotonext, 60000);
                ModelProxy.change("mainui", "counter", {type:4, value:60});
            }
            else
            {
                btn2.visible = false;
                btn.visible = true;
                btn1.visible = false;
                this.closeBtn.visible = true;
                btn.label = "确定";
            }
            this.setTxt(_loc_3);
            list.array = _loc_5;
            list.renderHandler = new Handler(this.itemRender);
            return;
        }// end function

        private function itemRender(param1:Component, param2:int) : void
        {
            if (param2 < list.length)
            {
                (param1 as FlashItem).data = param1.dataSource;
            }
            return;
        }// end function

        override protected function initialize() : void
        {
            super.initialize();
            this.init();
            return;
        }// end function

        public function init() : void
        {
            this.visible = false;
            this.x = GlobalLayer.instance.root.stage.stageWidth - this.width >> 1;
            this.y = GlobalLayer.instance.root.stage.stageHeight - this.height >> 1;
            btn.label = "确定";
            btn.labelFont = "宋体";
            btn.addEventListener(MouseEvent.CLICK, this.onBtn);
            this.setTxt("xxxx");
            btn2.label = "进入下一层";
            btn2.labelFont = "宋体";
            btn2.addEventListener(MouseEvent.CLICK, this.onBtn2);
            btn1.addEventListener(MouseEvent.CLICK, this.onBtn1);
            this.addEventListener(MouseEvent.MOUSE_DOWN, this.onDrag);
            this.addEventListener(MouseEvent.MOUSE_OUT, this.onOut);
            this.addEventListener(MouseEvent.MOUSE_UP, this.onOut);
            closeBtn.addEventListener(MouseEvent.CLICK, this.onClose);
            GlobalLayer.instance.root.addEventListener(Event.RESIZE, this.resizeHandler);
            return;
        }// end function

        private function onBtn1(event:MouseEvent) : void
        {
            this.close();
            ModelProxy.change("zone", "exitInstance", null);
            return;
        }// end function

        private function onBtn(event:MouseEvent) : void
        {
            this.close();
            if (this._items.length > 0)
            {
                ModelProxy.change("mainui", "itemEffect", this._items);
            }
            return;
        }// end function

        private function onBtn2(event:MouseEvent) : void
        {
            this.visible = false;
            this.gotonext();
            if (this._items.length > 0)
            {
                ModelProxy.change("mainui", "itemEffect", this._items);
            }
            return;
        }// end function

        private function gotonext() : void
        {
            if (this.nextmapid > 0)
            {
                PluginManager.instance.sendToServer("instance", CMDInstance.NextTianguan, this.nextmapid);
                this.nextmapid = 0;
            }
            else if (!this.canceled)
            {
                ModelProxy.change("zone", "exitInstance", null);
            }
            this.clearTimer();
            this.close();
            return;
        }// end function

        private function setTxt(param1:String) : void
        {
            label_tips.text = "完成副本<font color =\'#53b436\'>" + param1 + "</font>, 获得:";
            return;
        }// end function

        private function onDrag(event:MouseEvent) : void
        {
            if (event.localX > 0 && event.localX < GlobalLayer.instance.root.stageWidth && event.localY > 0 && event.localY < GlobalLayer.instance.root.stageHeight)
            {
                this.startDrag();
                event.stopImmediatePropagation();
            }
            return;
        }// end function

        private function onOut(event:MouseEvent) : void
        {
            this.stopDrag();
            return;
        }// end function

        public function cancel() : void
        {
            this.canceled = true;
            return;
        }// end function

        private function onClose(event:MouseEvent) : void
        {
            this.close();
            return;
        }// end function

        public function close() : void
        {
            this.visible = false;
            this.clearTimer();
            return;
        }// end function

        override public function set visible(param1:Boolean) : void
        {
            if (this.visible != param1)
            {
                Server.instance.send(91, CMDJueZhan.TIAN_GUAN_PROGRESS, null);
            }
            super.visible = param1;
            return;
        }// end function

        public function clearTimer() : void
        {
            if (this._timeID)
            {
                clearTimeout(this._timeID);
                this._timeID = 0;
            }
            return;
        }// end function

        private function resizeHandler(event:Event) : void
        {
            this.x = GlobalLayer.instance.root.stage.stageWidth - this.width >> 1;
            this.y = GlobalLayer.instance.root.stage.stageHeight - this.height >> 1;
            return;
        }// end function

    }
}
